import type { App } from "vue"
import { createRouter, createWebHistory } from "vue-router"
import type { RouteRecordRaw } from "vue-router"
import type { AppRouteModule } from "./type"
import Layout from "@/layout/index.vue"
const constantRoutes: AppRouteModule[] = [
  {
    path: "/",
    component: Layout,
    redirect: {
      name: "Home"
    },
    children: [
      {
        name: "Home",
        path: "/home",
        component: () => import("@/view/home/index.vue")
      }
    ]
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/view/login/index.vue")
  },
  {
    path: "/:pathMatch(.*)*",
    name: "NotFound",
    code: "noFound",
    hidden: true,
    component: () => import("@/view/noFound")
  }
]

const router = createRouter({
  routes: constantRoutes as RouteRecordRaw[],
  history: createWebHistory(),
  scrollBehavior: () => ({ left: 0, top: 0 })
})

export const setupRouter = (app: App<Element>) => {
  app.use(router)
}

export { router }
